#ifndef JREADWRITELOCK_H
#define JREADWRITELOCK_H

#include "jthreadpool_global.h"

// - class JReadWriteLock -

class JReadWriteLockPrivate;
class QReadWriteLock;

/**
 * @brief The JReadWriteLock class
 */
class JTHREADPOOL_EXPORT JReadWriteLock
{
public:
    /**
     * @brief The RecursionMode enum
     */
    enum RecursionMode { NonRecursive, Recursive };

    /**
     * @brief JReadWriteLock
     */
    JReadWriteLock();

    /**
     * @brief JReadWriteLock
     * @param recursionMode
     */
    JReadWriteLock(RecursionMode recursionMode);
    ~JReadWriteLock();

    /**
     * @brief lockForRead
     */
    void lockForRead();

    /**
     * @brief tryLockForRead
     * @return
     */
    bool tryLockForRead();

    /**
     * @brief tryLockForRead
     * @param timeout
     * @return
     */
    bool tryLockForRead(int timeout);

    /**
     * @brief lockForWrite
     */
    void lockForWrite();

    /**
     * @brief tryLockForWrite
     * @return
     */
    bool tryLockForWrite();

    /**
     * @brief tryLockForWrite
     * @param timeout
     * @return
     */
    bool tryLockForWrite(int timeout);

    /**
     * @brief unlock
     */
    void unlock();

    /**
     * @brief JReadWriteLock
     * @param base
     */
    JReadWriteLock(QReadWriteLock *base);

    /**
     * @brief base
     * @return
     */
    QReadWriteLock *base() const;

private:
    J_DISABLE_COPY(JReadWriteLock)
    JReadWriteLockPrivate *d;
};

// - class JReadLocker -

class JReadLockerPrivate;

/**
 * @brief The JReadLocker class
 */
class JTHREADPOOL_EXPORT JReadLocker
{
public:
    /**
     * @brief JReadLocker
     * @param readWriteLock
     */
    JReadLocker(JReadWriteLock *readWriteLock);

    ~JReadLocker();

    /**
     * @brief unlock
     */
    void unlock();

    /**
     * @brief relock
     */
    void relock();

    /**
     * @brief readWriteLock
     * @return
     */
    JReadWriteLock *readWriteLock() const;

private:
    J_DISABLE_COPY(JReadLocker)
    JReadLockerPrivate *d;
};

// - class JWriteLocker -

class JWriteLockerPrivate;

/**
 * @brief The JWriteLocker class
 */
class JTHREADPOOL_EXPORT JWriteLocker
{
public:

    /**
     * @brief JWriteLocker
     * @param readWriteLock
     */
    JWriteLocker(JReadWriteLock *readWriteLock);
    ~JWriteLocker();

    /**
     * @brief unlock
     */
    void unlock();

    /**
     * @brief relock
     */
    void relock();

    /**
     * @brief readWriteLock
     * @return
     */
    JReadWriteLock *readWriteLock() const;

private:
    J_DISABLE_COPY(JWriteLocker)
    JWriteLockerPrivate *d;
};

#endif // JREADWRITELOCK_H

